package com.atguigu.spring.demo12;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class WindowCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        // 1、通过 ConditionContext 对象获取当前环境信息
        Environment environment = context.getEnvironment();

        // 2、从环境信息中获取当前所在操作系统相关信息
        String osInfo = environment.getProperty("os");

        // 3、检查当前操作系统是否是 WINDOWS
        return osInfo.toUpperCase().contains("WINDOWS");
    }
}
